#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QString>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 菜单栏初始化
    initMenu();

    // 退出
    connect(qt, &QAction::triggered, this, &QMainWindow::close);



}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initMenu(void)
{
    // 创建菜单
    QMenu *file = new QMenu("文件(&F)");
    QMenu *debug = new QMenu("调试(&D)");

    // 添加菜单
    ui->menubar->addMenu(file);
    ui->menubar->addMenu(debug);

    // 添加新建文件菜单项
    newf = new QAction(QIcon(":/icon/file4.png"), "新建文件");
    newf->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
    file->addAction(newf);

    // 添加保存文件菜单项
    save = new QAction(QIcon(":/icon/past.png"), "保存文件");
    save->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
    file->addAction(save);

    // 添加打印菜单栏
    pr = new QAction(QIcon(":/icon/printer.png"), "打印");
    pr->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
    file->addAction(pr);

    // 添加退出菜单栏
    qt = new QAction(QIcon(":/icon/exit.png"), "退出");
    qt->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
    file->addAction(qt);

    return;
}
